const ImgConfig = {
  width: 20,
  height: 20
}
const CloakConfig = {
  image: null,
  x: 0,
  y: 0,
  width: 25,
  height: 25
}
export const ImgType = {
  mine: require('../images/mine.png'),
  block: require('../images/block.png'),
  flag: require('../images/flag.png'),
  one: require('../images/1.png'),
  two: require('../images/2.png'),
  three: require('../images/3.png'),
  four: require('../images/4.png'),
  five: require('../images/5.png'),
  six: require('../images/6.png'),
  seven: require('../images/7.png'),
  eight: require('../images/8.png'),
  none: null
}
export function initLoad() {
  for (let src in ImgType) {
    if (src=='none') continue
    let img = new Image()
    img.src = ImgType[src]
    ImgType[src] = img
  }
}


export class Img {
  // 初始化
  constructor(config, src = ImgConfig.block) {
    this.cellCF = config
    this.config = JSON.parse(JSON.stringify(CloakConfig))

    this.setPosition(config)
    this.setCloak(src)
  }
  // 设置image实例
  setImage(img) {
    this.image = img
  }
  // 设置图片 - 解除遮挡
  set(src) {
    this.config.image = src

    this.config.width = ImgConfig.width
    this.config.height = ImgConfig.height
    this.setPosition(this.cellCF)
  }
  // 设置flag
  setFlag() {
    this.config.width = ImgConfig.width
    this.config.height = ImgConfig.height
    this.id = 'flag' + this.config.x + '.' + this.config.y
    this.setPosition(this.cellCF)
  }
  // 设置
  setCloak(src) {
    this.config.image = src
  }
  // 设置位置
  setPosition(config) {
    this.config.x = config.x + (config.width - this.config.width) / 2
    this.config.y = config.y + (config.height - this.config.height) / 2
  }
}
